<?php
//
// +---------------------------------------------------------------------------------+
// | Package: EezeeSite Core                                                         |
// +---------------------------------------------------------------------------------+
// | Copyright (C) 2006  EezeeSite Development Team                                  |
// +---------------------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or                   |
// | modify it under the terms of the GNU General Public License                     |
// | as published by the Free Software Foundation; either version 2                  |
// | of the License, or (at your option) any later version.                          |
// |                                                                                 |
// | This program is distributed in the hope that it will be useful,                 |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                  |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                   |
// | GNU General Public License for more details.                                    |
// |                                                                                 |
// | You should have received a copy of the GNU General Public License               |
// | along with this program; if not, write to the Free Software                     |
// | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. |
// +---------------------------------------------------------------------------------+
// | Author: Mayukh De <mayukhde@gmail.com>                                          |
// +---------------------------------------------------------------------------------+
//

class ESSystem
{
    var $clientCheckList = array('config', 'DB', 'tables', 'tpls', 'htaccess', 'installLock');
    var $coreCheckList = array('dirPerms');
    var $sysObject;
    
    function systemCheck($checkListType, &$sysObject, $mode, $checkPoint = null)
    {
        $this->sysObject = $sysObject;
        if ($checkPoint) {
            if (in_array($checkPoint, $this->$checkListType)) {
                $this->executeCheck($checkPoint, $mode);
            } else {
                $this->sysObject->response->raiseESError(sprintf($GLOBALS['ES']['LANG']['SYSERROR']['INVALID'], $checkPoint), 'log');
            }
        } else {
            foreach ($this->$checkListType as $k => $v) {
                $this->executeCheck($v, $mode);
            }
        }
        return;
    }
    
    function executeCheck($checkPoint, $mode)
    {
        if (method_exists($this->sysObject, $checkPoint.$mode)) {
            call_user_func(array(&$this->sysObject, $checkPoint.$mode));
        } else {
            $this->sysObject->response->raiseESError(sprintf($GLOBALS['ES']['LANG']['SYSERROR']['UNHANDLED'], $checkPoint, $mode), 'log');
        }
        return;
    }
    
    function chmod($resource, $mode = 777)
    {
        $mode = (is_int($mode)) ? $mode : int($mode);
        if (OS_UNIX) {
            if (passthru('chmod -R '.$mode.' '.$resource)) {
                return true;
            } else {
                return false;
            }
        } elseif (OS_WINDOWS) {
            return true;
        } else {
            return false;
        }
    }
}

?>